package com.ljw;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;

public class MainFrameCanvas extends JFrame {

	private Character character;
	
	public static void main(String[] args){
		MainFrameCanvas mainFrame = new MainFrameCanvas();
		mainFrame.run();
	}
	
	private void init(){
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(100, 100, 300, 300);
	}
	
	private void run() {
		init();
		Canvas canvas = new Canvas();
		canvas.setBackground(Color.WHITE);//배경을 흰색으로
		canvas.setSize(300, 300);
		this.add(canvas);
		
		Toolkit tk = Toolkit.getDefaultToolkit();
		character = new Character(tk);
		
		canvas.createBufferStrategy(2);
		BufferStrategy bs = canvas.getBufferStrategy();
		//c = canvas;
	
		draw(bs);
	}

	private void draw(BufferStrategy bs) {
		Graphics g = bs.getDrawGraphics();
		while(true){
			for(int i=0; i<character.getImg().length; i++){
				g.clearRect(0, 0, 300, 300);
				g.drawImage(character.getImg()[i], 100 + i*10, 100 +i*10, this);
				try{
					Thread.sleep(100);
				}catch(Exception e){
					e.printStackTrace();
				}
				if(!bs.contentsLost())bs.show();
			}
			
		}
	}
	
	
}